<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>hello vue组件-全局组件</title>
    <link rel="stylesheet" type="text/css" href="./lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="./css/vue2-animate.css" type="text/css">

    <script type="text/javascript" src="./lib/vue/vue.js"></script>
    <script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/bootstrap/js/bootstrap.js"></script>
    <style>

    </style>

</head>

<body>

    <div id="box" class="container">
        动态组件 <component :is="one"></component>
        <div class="row">
            <button @click="componentA" type="button" class="btn btn-primary">组件一</button>
            <button @click="componentB" type="button" class="btn btn-primary">组件二</button>
        </div>
    </div>

</body>


<script>
    var v = new Vue({
        el: '#box',
        data: {
            one: 'cp1'
        },
        methods: {
            componentA() {
                this.one = 'cp1';
            },
            componentB() {
                this.one = 'cp2';
            }
        },
        components: {
            'cp1': { // 组件ID不能与html tag同名
                template: '<h2>aaaaaa</h2>'
            },
            'cp2': {
                template: '<h2>bbbbbb</h2>'
            }
        }

    });
</script>

</html>